package de.tudarmstadt.ukp.wikisniffer.userstudy.evaluation;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class GroupedAnswer {
	
	private long time;
	private List<String> questions;
	private List<String> answers;
	

	public GroupedAnswer(String[] propertiesAsArray, int lastStart,
			int lastFinish) {
		
		Date startDate = new Date();
		startDate.setTime(Long.valueOf(propertiesAsArray[lastStart].split("\t")[1]));
		
		Date endDate = new Date();
		endDate.setTime(Long.valueOf(propertiesAsArray[lastStart + 1].split("\t")[1]));
		
		time = endDate.getTime() - startDate.getTime();

		questions = new ArrayList<String>();
		answers = new ArrayList<String>();
		
		for(int n=lastStart;n<=lastFinish;n++){
			if(propertiesAsArray[n].startsWith("ENDED")){
				questions.add(propertiesAsArray[n].split("\t")[2]);
				answers.add(propertiesAsArray[n].split("\t")[4]);
			}
		}
	}

	public void addToProperties(int k) {
		
		if(questions.size()!=4)
		{
//			System.out.println("Not correct length of questions...");
			return;
		}
		
		VpEvaluator.vpEvaluator.addToProperties("time_stop_thema_" + k ,  String.valueOf(time));
		VpEvaluator.vpEvaluator.addToProperties("frage_" + k + "_1" ,  questions.get(0));
		VpEvaluator.vpEvaluator.addToProperties("frage_" + k + "_1_answer" ,  answers.get(0));
		VpEvaluator.vpEvaluator.addToProperties("frage_" + k + "_2" ,  questions.get(1));
		VpEvaluator.vpEvaluator.addToProperties("frage_" + k + "_2_answer" ,  answers.get(1));
		VpEvaluator.vpEvaluator.addToProperties("frage_" + k + "_3" ,  questions.get(2));
		VpEvaluator.vpEvaluator.addToProperties("frage_" + k + "_3_answer" ,  answers.get(2));
		VpEvaluator.vpEvaluator.addToProperties("frage_" + k + "_4" ,  questions.get(3));
		VpEvaluator.vpEvaluator.addToProperties("frage_" + k + "_4_answer" ,  answers.get(3));	
	}

}
